﻿namespace Suture.Tests
{
    using System;
    using System.CodeDom.Compiler;
    using System.IO;
    using System.Reflection;

    using Microsoft.CSharp;

    using NUnit.Framework;

    using Suture.StubGeneration;

    [TestFixture]
    public class ThirdPartyStubGeneratorTests
    {
        [SetUp]
        public void Setup()
        {
            var provider = new CSharpCodeProvider();
            var compilerparams = new CompilerParameters { GenerateExecutable = false, GenerateInMemory = false };
            compilerparams.ReferencedAssemblies.Add(typeof(IStubGenerator).Assembly.GetName().Name + ".dll");

            var results = provider.CompileAssemblyFromFile(compilerparams, "FakeStubGenerator.cs");// CompileAssemblyFromSource(compilerparams, code);    
          
            Assembly.LoadFile(results.PathToAssembly);
        }

        [Test, Ignore("Needs to delegate to new app domain")]
        public void Should_use_thirdparty_stub_generator()
        {
            var result = Builder.For<MyClass>().Build() as MyClass;

            Assert.That(result.Foo, Is.EqualTo("DummyValue"));
        }

        public class MyClass
        {
            public MyClass(string foo)
            {
                this.Foo = foo;
            }

            public string Foo { get; private set; }
        }
    }
}